﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace Common.DbHelper.BaseHelper
{
    /// <summary>
    /// 作者：赵虎
    /// 时间：2010-2-9
    /// 功能：数据库访问基础类
    /// </summary>
    public abstract class BaseData
    {
        /// <summary>
        /// 当前连接数据库字符串
        /// </summary>
        public string ConnectionString
        {
            get
            {
                if (Connection == null) return string.Empty;
                if (Connection.State == ConnectionState.Open)
                    Connection.Close();
                return Connection.ConnectionString;
            }
        }

        /// <summary>
        /// 当前连接
        /// </summary>
        public DbConnection Connection { get; set; }

        /// <summary>
        /// 当前命令对像
        /// </summary>
        public DbCommand Command { get; set; }

        /// <summary>
        /// 当前适配器
        /// </summary>
        public DbDataAdapter Adapter { get; set; }

        public BaseData(){}

        /// <summary>
        /// 构造指定的数据库访问对像
        /// </summary>
        /// <param name="conn">连接对像</param>
        /// <param name="cmd">命令对像</param>
        /// <param name="reader">阅读器对像</param>
        /// <param name="adapter">适配器对像</param>
        public BaseData(DbConnection conn, DbCommand cmd, DbDataAdapter adapter)
        {
            this.Connection = conn;
            this.Command = cmd;
            this.Adapter = adapter;
        }
    }
}
